package org.linlinjava.litemall.db.service;

 
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.linlinjava.litemall.db.dao.LumiereSubscribeUserLogMapper;
import org.linlinjava.litemall.db.domain.LumiereSubscribeUserLog;
import org.linlinjava.litemall.db.domain.LumiereSubscribeUserLogExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LumiereSubscribeUserLogService extends MPJBaseServiceImpl<LumiereSubscribeUserLogMapper,LumiereSubscribeUserLog> {
    @Resource
    private LumiereSubscribeUserLogMapper lumiereSubscribeUserLogMapper;

    public List<LumiereSubscribeUserLog> querySelective(Integer payType,String name, Integer page,Integer limit, String sort, String order) {
        LumiereSubscribeUserLogExample example = new LumiereSubscribeUserLogExample();
        LumiereSubscribeUserLogExample.Criteria criteria = example.createCriteria();
        if(payType != null){
            criteria.andPayTypeEqualTo(payType);
        }

//        if(name != null){
//            criteria.andUserNameLike("%" + name + "%");
//        }

        criteria.andDeletedEqualTo(false);

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        if(page != null && limit != null){
            //PageHelper.startPage(page, limit);
        }
        return lumiereSubscribeUserLogMapper.selectByExample(example);
    }

    public int add(LumiereSubscribeUserLog lumiereSubscribeUserLog){
        return  lumiereSubscribeUserLogMapper.insertSelective(lumiereSubscribeUserLog);
    }

    public LumiereSubscribeUserLog querySubscribeById(Integer id){
        return lumiereSubscribeUserLogMapper.selectByPrimaryKey(id);
    }

    public int update(LumiereSubscribeUserLog lumiereSubscribeUserLog){
        return lumiereSubscribeUserLogMapper.updateByPrimaryKeySelective(lumiereSubscribeUserLog);
    }

    public void deleteById(Integer id) {
        lumiereSubscribeUserLogMapper.logicalDeleteByPrimaryKey(id);
    }

    public LumiereSubscribeUserLog findById(Integer id) {
        return lumiereSubscribeUserLogMapper.selectByPrimaryKey(id);
    }

    public List<LumiereSubscribeUserLog> findByUserId(Integer subscribeUserId){
        LumiereSubscribeUserLogExample example = new LumiereSubscribeUserLogExample();
        example.or().andSubscribeUserIdEqualTo(subscribeUserId);
        return lumiereSubscribeUserLogMapper.selectByExample(example);
    }

    public List<LumiereSubscribeUserLog> listGiveLog(Integer userId,Integer buyType,String sort,String order){
        LumiereSubscribeUserLogExample example = new LumiereSubscribeUserLogExample();
        LumiereSubscribeUserLogExample.Criteria criteria = example.createCriteria();

        if(userId != null){
            criteria.andUserIdEqualTo(userId);
        }

        if(buyType != null){
            criteria.andBuyTypeEqualTo(buyType);
        }

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        return lumiereSubscribeUserLogMapper.selectByExample(example);
    }

}
